package tpo.lmhprovider.lmhprovider.controller;

import api.waresHouse.StockApi;
import com.github.pagehelper.PageInfo;
import dto.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import pojo.Stock_list;
import pojo.Stock_order;
import tpo.lmhprovider.lmhprovider.service.StockService;
import until.MyException;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

@RestController
public class StockController implements StockApi {
    @Autowired
    StockService stockService;
    @Override
    public Dto<Integer> addStock_order(GetStock getStock) {
        Dto dto=new Dto();
        try {
            dto.setObj(stockService.addStock_order(getStock));
        } catch (SQLException e) {
            dto.setSuccess(false);
            dto.setMsg("库存数量不足！请先补货，或取消该订单");
            e.printStackTrace();
        }
        return dto;
    }

    @Override
    public Dto<Integer> upStock_order(GetStock getStock) {
        Dto dto=new Dto();
        dto.setObj(stockService.upStock_order(getStock));
        return dto;
    }

    @Override
    public Dto<Integer> nextStock_order(Map map) {
        Dto dto=new Dto();
        try {
            dto.setObj(stockService.nextStock_order(map));
        } catch (SQLException e) {
            dto.setSuccess(false);
            dto.setMsg("库存数量不足！请先补货，或取消该订单");
            e.printStackTrace();
        }
        return dto;
    }

    @Override
    public Dto<PageInfo<ShowStock>> getStock_order(Map map) {
        Dto dto=new Dto();
        dto.setObj(stockService.getStock_order(map));
        return dto;
    }

    @Override
    public Dto<List<ShowStock_list>> getStock_list(Map map) {
        Dto dto=new Dto();
        dto.setObj(stockService.getStock_list(map));
        return dto;
    }

    @Override
    public Dto<Integer> delStock_order(String s) {
        Dto dto=new Dto();
        dto.setObj(stockService.delStock_order(s));
        return dto;
    }

    @Override
    public Dto<PageInfo<ShowDb_order>> getDb_order(Map map) {
        Dto dto=new Dto();
        dto.setObj(stockService.getDb_order(map));
        return dto;
    }

    @Override
    public Dto<Integer> addDb_order(GetStock getStock) {
        Dto dto=new Dto();
        try {
            dto.setObj(stockService.addDb_order(getStock));
        } catch (SQLException e) {
            dto.setSuccess(false);
            dto.setMsg("库存数量不足！请先补货，或取消该订单");
            e.printStackTrace();
        }
        return dto;
    }

    @Override
    public Dto<Integer> nextDb_order(Map map) {
        Dto dto=new Dto();
        dto.setObj(stockService.nextDb_order(map));
        return dto;
    }

    @Override
    public Dto<PageInfo<ShowStock_list>> getMingXi(Map map) {
        Dto dto=new Dto();
        dto.setObj(stockService.getMingXi(map));
        return dto;
    }
}
